<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <input type="text" v-model="firstname" /> +
      <input type="text" v-model="lastname" /> = <span>{{ fullname }}</span>
    </div>

    <script src="../Vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          firstname: "zhang",
          lastname: "san",
          // fullname: "zhangsan",
        },
        // 侦听属性
        // watch: {
        //   firstname(val) {
        //     this.fullname = val + this.lastname;
        //   },
        //   lastname(val) {
        //     this.fullname = this.firstname + val;
        //   },
        // },

        // 计算属性
        computed: {
          fullname() {
            return this.firstname + this.lastname;
          },
        },
      });
    </script>
  </body>
</html>
